package com.ruoyi.celoan.util;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ListUtils {
    public static <T> List<List<T>> split(List<T> resList, int count) {
        int SON_SIZE = count;
        int COPIES = (resList.size() + SON_SIZE - 1) / SON_SIZE;
        List<List<T>> sonLists = new ArrayList<>();
        Stream.<Integer>iterate(Integer.valueOf(0), n -> Integer.valueOf(n.intValue() + 1))
                .limit(COPIES)
                .parallel()
                .forEach(i -> {
                    int fromIndex = i.intValue() * SON_SIZE;
                    int toIndex = fromIndex + SON_SIZE;
                    sonLists.add(resList.stream().skip(fromIndex).limit(toIndex).collect(Collectors.toList()));
                });
        return sonLists;
    }

    public static <T> List<List<T>> splitList(List<T> resList, int count) {
        if (resList == null || count < 1) {
            return null;
        }
        List<List<T>> ret = new ArrayList<>();
        int size = resList.size();
        if (size <= count) {
            ret.add(resList);
        } else {
            int pre = size / count;
            int last = size % count;
            for (int i = 0; i < pre; i++) {
                List<T> itemList = new ArrayList<>();
                for (int j = 0; j < count; j++) {
                    itemList.add(resList.get(i * count + j));
                }
                ret.add(itemList);
            }
            if (last > 0) {
                List<T> itemList = new ArrayList<>();
                for (int j = 0; j < last; j++) {
                    itemList.add(resList.get(pre * count + j));
                }
                ret.add(itemList);
            }
        }
        return ret;
    }
}


/* Location:              D:\tuodayun\workspace\work\celoan-third-data-report-service-2.0.0-SNAPSHOT.jar!\BOOT-INF\classes\com\celoa\\util\ListUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */
